Component({
  options: {
    addGlobalClass: true,
  },
  properties: {
    imageList: {
      type: Object,
      value: []
    },
    presell: {
      type: Boolean,
      value: false
    }
  },
  data: {
    bannerListConfig: {
      indicatorDots: false,
      autoplay: false,
      interval: 4000,
      duration: 500,
    },
    currentIndex: 1,
    indexSum: null,
    imgHeights: [],
    fullUrls: [],
  },
  observers: {
    'imageList': function (imageList) {
      let fullUrls = [];
      if (imageList && imageList.length > 0) {

        let app = getApp()
        imageList.forEach(item => {
          fullUrls.push(app.toFullUrl(item))
        })
      }
      this.setData({ fullUrls })
    }
  },
  methods: {
    swiperChange(e) {
      this.setData({ currentIndex: e.detail.current + 1 })
    },
    toPreview(e) {
      let index = e.target.dataset.id;
      wx.previewImage({
        current: this.data.fullUrls[index],
        urls: this.data.fullUrls
      })
    },
    imageLoad: function (e) {
      let ratio = e.detail.width / e.detail.height;
      let imgHeights = this.data.imgHeights;
      imgHeights[e.target.dataset.id] = 710 / ratio;
      this.setData({ imgHeights })
    },
  }
});
